home *** CD-ROM | disk | FTP | other *** search
- PROGRAM Sample;
- uses crt;
-
- (* This is a Turbo Pascal program for testing PrettyPascal 1.0
- * The program simply writes a..y diagonally on the screen 6 times
- *)
-
- TYPE
- str26= string[26];
-
- var
- m: Integer;
-
- CONST
- str: str26 = 'abcdefghijklmnopqrstuvwxyz';
-
-
- Procedure display(m: integer; s: str26);
-
- (* Pre-cond : 0<=m<3 && s = string of alphabet
- * Post-cond: string s written diagonally twice
- *)
-
- var r, c: integer;
-
- begin
- (* demonstrate "if" constructs *)
- if m = 0 then { check value of m }
- c := 0
- ELSE IF m = 1 then
- c := 10
- else
- c := 20;(* c = 0, 10 or 20 depending on m *)
-
- { demonstrates "for" constructs }
- FOR r:=0 to 25 DO
- BEGIN
- gotoxy(r,c);
- write(s[r]); (* keep looping until r=25 *)
- c:= c + 1;
- END;
-
- { another demonstration of "if" construct }
- if m=0 then begin
- c := 5;
- end
- else if m=1 then
- BEGIN
- c := 15;
- END
- else
- begin
- c := 25;
- end; (* c = 5, 15 or 25 depending on m *)
-
- { demonstrates "while" construct }
- r := 0;
- WHILE r <> 25 do begin (* loop until r=25 *)
- gotoxy(r,c); (* position cursor for display *)
- write(s[r]); (* print character *)
- r:= r + 1;
- c:= c + 1;
- END
- end;
-
-
- BEGIN
- (* loop invariant P0 == 0<=m<3 and alphabet written m*2 times thus far *)
- m:=0; { P0 true }
- ClrScr;
- while m <> 3 do
- begin
- display ( m, str ); (* call display for writing str *)
- m:=m + 1;(* add 1 to m => P0 true *)
- END (* finished WITH loop end. *)
- END.